python join two lists as dictionary

40

# using zip()
# to convert lists to dictionary

# initializing lists
test_keys = ["Rash", "Kil", "Varsha"]
test_values = [1, 4, 5]
  
res = dict(zip(test_keys, test_values))
>>> from collections import ChainMap
>>> a = [{'a':1},{'b':2},{'c':1},{'d':2}]
>>> dict(ChainMap(*a))
{'b': 2, 'c': 1, 'a': 1, 'd': 2}

Comments

Submit
0 Comments